package com.gzedu.module.controller.curd;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gzedu.common.sys.controller.BaseController;
import com.gzedu.common.util.page.Page;
import com.gzedu.module.faced.curd.CurdButtonFacade;
import com.gzedu.module.faced.curd.CurdFormFacade;
import com.gzedu.module.faced.curd.CurdListFacade;
import com.gzedu.module.modle.curd.CurdForm;

@Controller
@RequestMapping("/curdForm")
public class CurdFormController extends BaseController{
	@Autowired
	private CurdFormFacade curdFormFacade;
	@Autowired
	private CurdListFacade curdListFacade;
	@Autowired
	private CurdButtonFacade curdButtonFacade;
	
	@RequestMapping("/getCurdFormInfo")
	@ResponseBody
	public Page getCurdFormInfo(HttpServletRequest request,HttpServletResponse response,int pageNo){
		Page page = curdFormFacade.getCurdFormInfo(null, pageNo);
		
		return page;
	}
	
	@RequestMapping("/add")
	public String add(HttpServletRequest request,HttpServletResponse response){
		return "/views/curd/commonListForm";
	}
	
	@RequestMapping("/update")
	public String update(HttpServletRequest request,HttpServletResponse response,Model model, String id){
		CurdForm curdForm = curdFormFacade.getById(id);
		List<CurdForm> curdFormList = curdFormFacade.selectByFormId(curdForm.getCurd_form_id());
		List<Map<String,Object>> curdList = curdListFacade.getByFormId(curdForm.getCurd_form_id());
		List<Map<String,Object>> curdButton = curdButtonFacade.getBtnInfoByFormId(curdForm.getCurd_form_id());
		model.addAttribute("curdFormList", curdFormList);
		model.addAttribute("curdList", curdList);
		model.addAttribute("curdButton", curdButton);
		return "/views/curd/commonListFormUpdate";
	}
}
